class Solution {
public:
    int findPeakElement(vector<int>& nums) {

        if(nums.size()==1) return 0;
        int left=0,right=nums.size()-1,ans=-1;
        while(left<=right)
        {
            int mid=(right-left)/2+left;
            if(mid+1>=nums.size()) return mid;
            if(nums[mid]<nums[mid+1])
            {
                left=mid+1;
            }
            else
            {
                //此时的mid可能是答案也可能不是
                ans=mid;
                right=mid-1;
            }
        }
        return ans;
    }
};